#!/usr/bin/python3
# coding=utf-8

# 常用函数的集合
import os
from utils.yamlUtil import YamlUtil

Global_Vars = YamlUtil().data_load()


def get_root_path():
    return Global_Vars.get("ROOT_PATH")


def get_env():
    return Global_Vars.get("RUNTIME_ENV")


def get_domain():
    return Global_Vars.get("DOMAIN")


def get_runtime_header():
    root_path = get_root_path()
    target_yaml_file = os.path.join(
        root_path, "configs", Global_Vars.get("RUNTIME_FILE")
    )
    runtime_vars = YamlUtil(target_yaml_file).data_load()
    runtime_header = (
        runtime_vars.get("admin_header")
        if "admin_header" in runtime_vars.keys()
        else None
    )
    return runtime_header


def get_account_info():
    """获取测试用账号信息"""
    target_env = get_env()
    user_info = Global_Vars.get(target_env).get("ACCT")
    return user_info


def get_testcase_list(test_module, test_yaml_file):
    testcase_list = None
    root_path = get_root_path()
    target_yaml_file = os.path.join(root_path, "testset", test_module, test_yaml_file)
    if os.path.exists(target_yaml_file):
        testcase_list = YamlUtil(target_yaml_file).data_load()
    else:
        raise FileNotFoundError(target_yaml_file)

    return testcase_list
